﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DLL.Entities;
using System.Xml.Serialization;
using System.Xml;
using DLL;
using System.IO;

namespace COM
{
    public partial class COM_Form : Form
    {

        public COM_Form()
        {
            InitializeComponent();
        }


        string cwd = System.IO.Directory.GetCurrentDirectory();

        private void btnXmlReader_Click(object sender, EventArgs e)
        {
            Radar Rad_Obj = new Radar();
            XmlSerializer serialization = new XmlSerializer(typeof(Radar));
            Rad_Obj = (Radar)XMLHandler.ReadXML("../../../RAD/bin/Radar_Serialized.xml", serialization);

            txtAltitude.Text =  Convert.ToString(Rad_Obj.Altitude);
            txtDirection.Text = Convert.ToString(Rad_Obj.Direction);
            txtDistance.Text = Rad_Obj.Distance;
            txtSpeed.Text = Rad_Obj.Speed;
        }

            

        private void timer1_Tick_1(object sender, EventArgs e)
        {
           

            if (File.Exists("../../../RAD/bin/Debug/RadStat_Serialized.xml"))
            {
                txtRadStatus.Text = "ONLINE!";

                try
                {
                    File.Delete("../../../RAD/bin/Debug/RadStat_Serialized.xml");
                }
                catch (Exception)
                {                    
                   
                }
            }
            else
            {
                txtRadStatus.Text = "OFFLINE!";
            }
        }
     
        private void timer3_Tick(object sender, EventArgs e)
        {
            try
            {
                Radar Radar_Obj = new Radar();
                XmlSerializer serializer = new XmlSerializer(typeof(Radar));
                Radar_Obj = (Radar)XMLHandler.ReadXML("../../../RAD/bin/Debug/Radar_Serialized.xml", serializer);


                txtSpeed.Text = Radar_Obj.Speed;
                txtDistance.Text = Convert.ToString(Radar_Obj.Distance);
                txtAltitude.Text = Radar_Obj.Altitude;
                txtDirection.Text = Convert.ToString(Radar_Obj.Direction);



            }
            catch (FileNotFoundException ex)
            {
                Utility.LogFile(ex.ToString());
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (File.Exists("../../../MIS/bin/Debug/missileStat_Serialized.xml"))
            {
                txtMISStatus.Text = "ONLINE!";

                try
                {
                    File.Delete("../../../MIS/bin/Debug/missileStat_Serialized.xml");
                }
                catch (Exception)
                {

                }
            }
            else
            {
                txtMISStatus.Text = "OFFLINE!";
            }


        }    

       
    }


}
